<?php

namespace oneStep;

define(
    'HTTPCODE',
    [
        200,
        404,
    ]
);

class Response
{
    public static $headerInfo;

    /**
     * @param $data
     * @param int $httpCode
     */
    public function send($data, $httpCode = 200)
    {
        header(self::$headerInfo);
        if (!in_array($httpCode, HTTPCODE)) {
            $httpCode = HTTPCODE[0];
        }
        http_response_code($httpCode);
        $callback = $_REQUEST['callback'] ?? '';
        if ($callback) {
            echo $callback . '(' . $data . ')';
            exit();
        }
        echo $data;
    }

}